home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1320 / 1320.xpi / chrome / gmanager.jar / content / alert / alert.js < prev    next >
Text File  |  2010-01-22  |  6KB  |  203 lines

  1. // Gmail Manager
  2. // By Todd Long <longfocus@gmail.com>
  3. // http://www.longfocus.com/firefox/gmanager/
  4.  
  5. var gmanager_Alert = new function()
  6. {
  7.   this.__proto__ = new gmanager_BundlePrefix("gmanager-alert-");
  8.   
  9.   this.NOTIFY_ALERT_CLICKED  = "gmanager-alert-notify-clicked";
  10.   this.NOTIFY_ALERT_FINISHED = "gmanager-alert-notify-finished";
  11.   
  12.   this.FINAL_HEIGHT    = 100;
  13.   this.SLIDE_INCREMENT = 1;
  14.   this.SLIDE_TIME      = 10;
  15.   this.SWITCH_TIME     = 2000;
  16.   this.OPEN_TIME       = 2000;
  17.   
  18.   this.load = function()
  19.   {
  20.     // Unwrap the window arguments
  21.     if ("arguments" in window && window.arguments.length >= 1)
  22.     {
  23.       // window.arguments[0] : mail account
  24.       // window.arguments[1] : callback listener
  25.       
  26.       this._account = window.arguments[0];
  27.       this._callback = window.arguments[1];
  28.     }
  29.     
  30.     // Check if the account is specified
  31.     if (this._account == undefined)
  32.     {
  33.       // Close the window
  34.       window.close();
  35.     }
  36.     
  37.     // Set the account icon
  38.     var accountImage = document.getElementById("gmanager-alert-account-image");
  39.     accountImage.setAttribute("icontype", this._account.type);
  40.     accountImage.setAttribute("status", gmanager_Utils.toStyleStatus(this._account.status));
  41.     
  42.     // Set the account alias
  43.     var accountLabel = document.getElementById("gmanager-alert-account-label");
  44.     accountLabel.setAttribute("value", this._account.alias);
  45.     accountLabel.setAttribute("tooltiptext", this._account.alias);
  46.     
  47.     // Check if the account is logged in
  48.     if (this._account.loggedIn)
  49.     {
  50.       // Get the account snippets
  51.       this._snippets = this._account.getSnippets({});
  52.       
  53.       if (this._snippets === null || this._snippets.length === 0)
  54.       {
  55.         // Close the window
  56.         window.close();
  57.       }
  58.       
  59.       // Populate the first snippet
  60.       this.firstSnippet();
  61.     }
  62.     else
  63.     {
  64.       document.getElementById("gmanager-alert-navigation-hbox").collapsed = true;
  65.       document.getElementById("gmanager-alert-details-grid").collapsed = true;
  66.       document.getElementById("gmanager-alert-description").setAttribute("clickable", false);
  67.       document.getElementById("gmanager-alert-description").firstChild.nodeValue = this.getString("login");
  68.     }
  69.     
  70.     try {
  71.       var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  72.       
  73.       if (prefService !== null)
  74.       {
  75.         var branch = prefService.getBranch("alerts.");
  76.         
  77.         this.SLIDE_INCREMENT = branch.getIntPref("slideIncrement");
  78.         this.SLIDE_TIME = branch.getIntPref("slideIncrementTime");
  79.         this.OPEN_TIME = branch.getIntPref("totalOpenTime");
  80.       }
  81.     } catch(e) {
  82.       /* Preference branch error */
  83.     }
  84.     
  85.     sizeToContent();
  86.     
  87.     this.FINAL_HEIGHT = window.outerHeight;
  88.     
  89.     window.outerHeight = 1;
  90.     window.moveTo((screen.availLeft + screen.availWidth - window.outerWidth) - 10, screen.availHeight - window.outerHeight);
  91.     
  92.     setTimeout(gmanager_Alert._animateOpen, gmanager_Alert.SLIDE_TIME);
  93.   }
  94.   
  95.   this._populateSnippet = function(aIndex)
  96.   {
  97.     var snippet = this._snippets[aIndex];
  98.     
  99.     document.getElementById("gmanager-alert-count-label").value = this.getFString("count", [this._snippetIndex + 1, this._snippets.length]);
  100.     document.getElementById("gmanager-alert-from-label").value = gmanager_Utils.toUnicode(snippet.from);
  101.     document.getElementById("gmanager-alert-date-label").value = gmanager_Utils.toUnicode(snippet.date);
  102.     document.getElementById("gmanager-alert-subject-label").value = gmanager_Utils.toUnicode(snippet.subject);
  103.     document.getElementById("gmanager-alert-description").firstChild.nodeValue = gmanager_Utils.toUnicode(snippet.msg);
  104.   }
  105.   
  106.   this.nextSnippet = function()
  107.   {
  108.     if (this._isNext())
  109.       this._populateSnippet(++this._snippetIndex);
  110.   }
  111.   
  112.   this.previousSnippet = function()
  113.   {
  114.     if (this._isPrevious())
  115.       this._populateSnippet(--this._snippetIndex);
  116.   }
  117.   
  118.   this.firstSnippet = function()
  119.   {
  120.     this._snippetIndex = 0;
  121.     this._populateSnippet(this._snippetIndex);
  122.   }
  123.   
  124.   this.lastSnippet = function()
  125.   {
  126.     this._snippetIndex = this._snippets.length - 1;
  127.     this._populateSnippet(this._snippetIndex);
  128.   }
  129.   
  130.   this._isNext = function()
  131.   {
  132.     return (this._snippetIndex < this._snippets.length - 1);
  133.   }
  134.   
  135.   this._isPrevious = function()
  136.   {
  137.     return (this._snippetIndex > 0);
  138.   }
  139.   
  140.   this._animateOpen = function()
  141.   {
  142.     if (window.outerHeight < gmanager_Alert.FINAL_HEIGHT)
  143.     {
  144.       window.screenY -= gmanager_Alert.SLIDE_INCREMENT;
  145.       window.outerHeight += gmanager_Alert.SLIDE_INCREMENT;
  146.       setTimeout(gmanager_Alert._animateOpen, gmanager_Alert.SLIDE_TIME);
  147.     }
  148.     else
  149.       setTimeout(gmanager_Alert._slideshow, gmanager_Alert.SWITCH_TIME);
  150.   }
  151.   
  152.   this._animateClose = function()
  153.   {
  154.     if (window.outerHeight > 1)
  155.     {
  156.       window.screenY += gmanager_Alert.SLIDE_INCREMENT;
  157.       window.outerHeight -= gmanager_Alert.SLIDE_INCREMENT;
  158.       setTimeout(gmanager_Alert._animateClose, gmanager_Alert.SLIDE_TIME);
  159.     }
  160.     else
  161.     {
  162.       // Close the alert
  163.       gmanager_Alert.close();
  164.     }
  165.   }
  166.   
  167.   this._slideshow = function()
  168.   {
  169.     if (gmanager_Alert._isNext())
  170.     {
  171.       gmanager_Alert.nextSnippet();
  172.       setTimeout(gmanager_Alert._slideshow, gmanager_Alert.SWITCH_TIME);
  173.     }
  174.     else
  175.       setTimeout(gmanager_Alert._animateClose, gmanager_Alert.OPEN_TIME);
  176.   }
  177.   
  178.   this.click = function()
  179.   {
  180.     // Check if the callback listener is specified
  181.     if (this._callback != undefined && typeof this._callback.observe == "function")
  182.     {
  183.       // Notify the observer that the alert was clicked
  184.       this._callback.observe(null, gmanager_Alert.NOTIFY_ALERT_CLICKED, this._account.email);
  185.     }
  186.     
  187.     // Close the alert
  188.     gmanager_Alert.close();
  189.   }
  190.   
  191.   this.close = function()
  192.   {
  193.     // Close the window
  194.     window.close();
  195.     
  196.     // Check if the callback listener is specified
  197.     if (this._callback != undefined && typeof this._callback.observe == "function")
  198.     {
  199.       // Notify the observer that the alert has finished
  200.       this._callback.observe(null, gmanager_Alert.NOTIFY_ALERT_FINISHED, this._account.email);
  201.     }
  202.   }
  203. }